package com.yyx.springcloud.controller;

import com.yyx.springcloud.pojo.Payment;
import com.yyx.springcloud.pojo.Result;
import com.yyx.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * ClassName: PaymentController
 * Package: com.yyx.springcloud.controller
 * Description:
 *
 * @Author: yyx
 * @Create: 2025/7/23 - 15:16
 */
@Slf4j
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Autowired
    private PaymentService paymentService;


    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/feign/timeout")
    public String paymentFeignTimeOut(){
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return serverPort;
    }
    @PostMapping("/create")
    public Result create(@RequestBody Payment payment){
        int save=paymentService.save(payment);
        log.info("插入的结果：serverPort"+serverPort+save);
        return new Result(200,"成功 serverPort:"+serverPort,save);
    }
    @GetMapping("/get/{id}")
    public Result getPaymentById(@PathVariable("id")Long id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("插入的结果：serverPort:"+serverPort+payment);
        return new Result(200,"查询成功 serverPort:"+serverPort,payment);
    }
}
